﻿/// <reference path="../jquery.min.js" />
/// <reference path="../rsseasy.app.js" />
/// <reference path="../view.js" />


$(function () {
    var menudict = { "m1": "党建新闻", "m2": "专题活动", "m3": "网上课堂", "m4": "党建动态", "m8": "先进典型", "m9": "党建学习", "m90": "积分排名", "m91": "党员学习俱乐部" }

    var menusondict = { "m2": { "m5": "两学一做", "m6": "三严三实","m7": "三亮四带五规范" }, "m4": { "m18": "学校党建", "m19": "社会党建" } }

    var homepagenav = $("#homepagenav>tbody"), html = "<tr>";
    var count = 1;
    $.each(menudict, function (key, val) {
        html += '<td dataid="' + key + '"><img src="img/idx/' + key + '.png" /><a>' + val + '</a></td>';
        if (count++ % 3 == 0) {
            html += '</tr><tr>';
        }
    });
    html += '<td></td></tr>';


    var indexswitch = $("#indexswitch").find("ul");
    new Ajax("article/dynamic").get(function (josn) {

        var html = "",point="";
        $.each(josn, function (key,rows) {
            html += '<li dataid="' + rows["id"] + '"><a href="#articleviewpage"><img src="' + RssApp.UpHost + rows["ico"] + '" alt="" /></a><h2>' + rows["title"] + '</h2></li>';
            point += "<li></li>";
        });
        indexswitch.html(html).pageslide();

        indexswitch.find("li").click(function () {
            RssView.AjaxNews($(this).attr("dataid"));
        });

        $("#indexswitch").find("ol").html(point).find("li").first().addClass("current");

        $("#indexswitch").on("pageslideend", function (ev, json) {
            $("#minswitch li").removeClass("current").eq(json["curpage"] - 1).addClass("current");
        });
    });

    var articlelist = RssPage.articlelistpage, articleitem = $("#articleitem"), sonpage = RssPage.sonpage;
    homepagenav.html(html).find("td").click(function () {
        articlelist.title.empty();
        articleitem.empty();
        var adapter = $(this).attr("dataid");
        switch (adapter) {
            case "m2":
            case "m4":
                sonpage.title.html(menudict[adapter]);
                var html = "";
                var tmpdata = menusondict[adapter];
                $.each(tmpdata, function (key, val) {
                    html += '<div dataid="' + key + '"><img src="img/idx/' + key + '.png" /><a>' + val + '</a></div>';
                });
                sonpage.article.html(html).find("div").click(function () {
                    var tmp=$(this).attr("dataid");
                    getlist(tmpdata[tmp], tmp);
                });
                location.hash = "#sonpage";
                break;
            case "m90":
                break;
            default:
                getlist(menudict[adapter],adapter);
                break;
        }
    });

    function getlist(title,channelid)
    {
        articlelist.title.html(title);
        new Ajax("article/list").keyvalue("channelid", channelid.replace("m", "")).setloading(articlelist.article).getJson(function (data) {
            RssView.articlelist($("#articleitem"), data);
        });

        location.hash = "#articlelistpage"
    }
});
